<?php
    require_once($application_folder."/controllers/navigator.php");
    class Style extends navigator
    {
        function Style() 
        {
            parent::navigator();
            if ($this->session->userdata('logged_in') != TRUE)
            {
                redirect(base_url().'login');
            }
            $this->load->model('style_m','stil');
            $this->carabiner->css('colorpicker.css');
            $this->carabiner->js('colorpicker.js');
        }
        function pogledaj_uredi_stil($id=NULL,$template=NULL){
            $this->carabiner->js('anketa/jquery.validate-anketa.js');
            $this->data['strana'] = 'style';
            $this->data['podstrana'] = 'edit_style';
            if($template!=NULL){
                $this->data['style_data'] = $this->stil->lisaj_podatke_stila($id);
            }else if($id!=NULL){
                    $this->data['style_data'] = $this->stil->lisaj_podatke_stila($id);
                }
                $this->data['styles'] = $this->stil->lisaj_stilove();
            $this->navigate($this->data['strana'].'/'.$this->data['podstrana']);
        }
        function citaj_klase_stilova($custom_or_default){
            //$this->stil->citaj_klase_stilova(array('style_id'=>$_POST['id']),TRUE);
            $this->stil->citaj_klase_stilova(array($custom_or_default=>$_POST['id']),TRUE);
        }
        function uredi_klase_stilova(){ 
            if($this->stil->uredi_klase_stilova($_POST['id'], $_POST['name'], $_POST['style'])){
                echo json_encode(array('sucess'=>true));
            } else{
                echo json_encode(array('sucess'=>false));
            }
        }
        function kreiraj_klase_stilova(){ 
            if($this->stil->kreiraj_klase_stilova($_POST['name'], $_POST['style'])){
                echo json_encode(array('sucess'=>true));
            } else{
                echo json_encode(array('sucess'=>false));
            }
        }
        function brisi_podeseni_stil($id){
            if($this->stil->brisi_podeseni_stil($id)){
                echo json_encode(array('success'=>true));
            } else{
                echo json_encode(array('success'=>false));
            }
        }
        
        function kreiraj_info($type){
            header('Location:'.base_url().'anketa/uredi_anketu/list_polls/true/'.$type);
        }
    }
?>